//
//  YLMainViewController.swift
//  weiBo
//
//  Created by 杨雷 on 2016/11/30.
//  Copyright © 2016年 Yang.L. All rights reserved.
//

import UIKit

class YLMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置自定义tabbar
        let ylTabBar = YLTabBar()
        setValue(ylTabBar, forKey: "tabBar")
        
        //设置代理
//        ylTabBar.YLDelegate = self
        
        ylTabBar.callBack = {[weak self] in
            
            print("点加号")
            
        }
        
        //添加子视图控制器
        addChildViewController(childController: YLHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(childController: YLMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(childController: YLDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(childController: YLMineTableViewController(), imageName: "tabbar_profile", title: "我的")
        
        
        
    }
    
    func addChildViewController(childController: UIViewController, imageName: String, title: String) {
        //设置tabbar图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //选中样式的图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        //title
        childController.title = title
        //颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: UIControlState.selected)
        //大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12)], for: UIControlState.normal)
        
        
        //nav控制器
        let nav = YLNavigationViewController(rootViewController: childController)
         
        //添加姿势图控制器
        addChildViewController(nav)
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}

//extension YLMainViewController :YLTabBarDelegate {
//    
//    func didSelectedBtn() {
//        print("代理")
//    }
//    
//}














